package 反转链表;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 206.反转链表
 * @date 2022/10/22 16:41
 */
public class Demo206 {
    public ListNode reverseList(ListNode head) {
        ListNode pre=null;
        ListNode cur=head;
        ListNode temp=null;
        while (cur!=null){
            temp=cur.next;
            cur.next=pre;
            pre=cur;
            cur=temp;
        }
        return cur.next;
    }
    /**
     *Definition for singly-linked list.
     * **/
     public class ListNode {
         int val;
         ListNode next;
         ListNode() {}
         ListNode(int val) { this.val = val; }
         ListNode(int val, ListNode next) { this.val = val; this.next = next; }
     }

}
